/*
 * Copyright ©2021 su binglun(9085309@qq.com). All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 *---------------------------------------------------------------------
 *-                                                                   -
 *-           Website : http://phoenix.sunny360.cn/                   -
 *-                                                                   -
 *---------------------------------------------------------------------
 */
package cn.sunny360.core.wrapper;

import io.vertx.core.Promise;
import io.vertx.core.json.JsonObject;
import io.vertx.sqlclient.Tuple;

import java.util.List;
import java.util.Optional;

public interface DBWrapper {
    Promise<Optional<JsonObject>> findOne(String sql, Tuple param);
    Promise<List<JsonObject>> findList(String sql, Tuple param);
    Promise<Integer> insert(String sql, Tuple param);
    Promise<Integer> update(String sql, Tuple param);
    Promise<Integer> delete(String sql, Tuple param);
    Promise<Boolean> executeWithTrans(List<SQLTuple> sqls);
    Promise<Boolean> executeWithTrans(SQLTuple ... sqls);
    public static class SQLTuple {
        private String sql;
        private Tuple param;

        public SQLTuple(String sql, Tuple param) {
            this.sql = sql;
            this.param = param;
        }

        public String getSql() {
            return sql;
        }

        public void setSql(String sql) {
            this.sql = sql;
        }

        public Tuple getParam() {
            return param;
        }

        public void setParam(Tuple param) {
            this.param = param;
        }

        @Override
        public String toString() {
            return "sql:["+sql+"]\tparam:" + param.deepToString();
        }
    }
}
